package com.lebang.medicalInquiry.controller;


import com.lebang.medicalInquiry.constant.ConfigEnum;
import com.lebang.medicalInquiry.constant.ResponseEnum;
import com.lebang.medicalInquiry.response.Callback;
import com.lebang.medicalInquiry.response.JsonData;
import com.lebang.medicalInquiry.service.ConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @version V1.0
 * @author: zpc
 * @date:
 */
@RequestMapping("/api/config")
@Api(tags = "配置相关")
@Validated
@RestController
public class ConfigApi {

    @Autowired
    private ConfigService configService;

    @GetMapping("/config")
    @ApiOperation("获取config")
    public JsonData getConfigByCode(HttpServletRequest request, HttpServletResponse response,
                                    Integer code
    ) {
        if (code.equals(ConfigEnum.ALIPAY.getConfigType())||code.equals(ConfigEnum.WXPAY.getConfigType())) {
            return Callback.fail(ResponseEnum.FAIL.getCode(), ResponseEnum.FAIL.getMemo());
        }
        return Callback.success(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMemo(), configService.getByCode(code));

    }
}
